﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XChipTool.Enties
{
    public class SettingFileNew
    {
        private List<SettingData> commonSetting;
        private List<SettingData> setting;
        private List<SettingData> tveSetting;
        private List<SettingData> iqSetting;
        private List<SettingData> sensorSetting;

        /// <summary>
        /// Common文件夹
        /// </summary>
        public List<SettingData> CommonSetting
        {
            get
            {
                if (null == commonSetting)
                {
                    commonSetting = new List<SettingData>();
                }
                return commonSetting;
            }

            set
            {
                commonSetting = value;
            }
        }
        /// <summary>
        /// setting 文件夹
        /// </summary>
        public List<SettingData> Setting
        {
            get
            {
                if (null == setting)
                {
                    setting = new List<SettingData>();
                }
                return setting;
            }

            set
            {
                setting = value;
            }
        }
        /// <summary>
        /// Tve文件夹
        /// </summary>
        public List<SettingData> TveSetting
        {
            get
            {
                if (null == tveSetting)
                {
                    tveSetting = new List<SettingData>();
                }
                return tveSetting;
            }

            set
            {
                tveSetting = value;
            }
        }
        /// <summary>
        /// Iq 文件夹
        /// </summary>
        public List<SettingData> IqSetting
        {
            get
            {
                if (null == iqSetting)
                {
                    iqSetting = new List<SettingData>();
                }
                return iqSetting;
            }

            set
            {
                iqSetting = value;
            }
        }
        /// <summary>
        /// Sensor 文件夹
        /// </summary>
        public List<SettingData> SensorSetting
        {
            get
            {
                if (null == sensorSetting)
                {
                    sensorSetting = new List<SettingData>();
                }
                return sensorSetting;
            }

            set
            {
                sensorSetting = value;
            }
        }



        /// <summary>
        /// 序号
        /// </summary>
        public string SettingNo { get; set; }
        /// <summary>
        /// 传输
        /// </summary>
        public string TransferName { get; set; }
        /// <summary>
        /// 视频
        /// </summary>
        public string VideoName { get; set; }


        /// <summary>
        /// 传输
        /// </summary>
        public string TransferHex { get; set; }
        /// <summary>
        /// 视频
        /// </summary>
        public string VideoHex { get; set; }

        /// <summary>
        /// 提示
        /// </summary>
        public string Tips
        {
            get
            {
                if (TransferName != null)
                {
                    return TransferName + VideoName + "_" + TipsSettingNo;
                }
                else
                {
                    return TransferName + VideoName;
                }
            }

        }
        public string TipsSettingNo { get; set; }
        /// <summary>
        /// 菜单数量  用于计算菜单结构长度 计算公式 844*4* 菜单数量
        /// </summary>
        public int MenuNo { get; set; }
        /// <summary>
        /// 语言数量 
        /// </summary>
        public int LanguageNo { get; set; }
        /// <summary>
        /// 是否勾选版本号
        /// </summary>
        public bool IsVersion { get; set; }

        /// <summary>
        /// 存放指示
        /// </summary>
        public string Mode { get; set; }

        /// <summary>
        /// 模式
        /// </summary>
        public int patternNo { get; set; }
        /// <summary>
        /// 制式
        /// </summary>
        public int formatNo { get; set; }
        /// <summary>
        ///是否存在制式
        /// </summary>
        public bool Standarddisplay { get; set; }

        /// <summary>
        /// 地址    需要添加 0xfffd,0x20,0xfffe,0x00, 为头文件
        /// </summary>
        public uint hexAddr { get; set; }
        /// <summary>
        /// 视频格式的值
        /// </summary>

        public uint hexVal { get; set; }

        public string hexNote { get; set; }
        /// <summary>
        /// 软件要配置的寄存器数组
        /// </summary>
        public string HexOut { get { return $"0x{hexAddr.ToString("X").PadLeft(4, '0')},0x{hexVal.ToString("X").PadLeft(2, '0')},//{hexNote}"; } }

    }



    public class SettingData
    {
        public string FilePath { get; set; }
        /// <summary>
        /// 文件名称
        /// </summary>
        public string FileName { get; set; }
        /// <summary>
        /// 制式名称
        /// </summary>
        public string StandardName
        {
            get
            {
                if (FileName.ToLower().Contains("ahd"))
                {
                    return "AHD";
                }
                else if (FileName.ToLower().Contains("thd"))
                {
                    return "THD";
                }
                else if (FileName.ToLower().Contains("chd"))
                {
                    return "CHD";
                }
                else if (FileName.ToLower().Contains("cvbs"))
                {
                    return "CVBS";
                }
                else
                {
                    return null;
                }

            }
        }

        public List<string> VFormat = new List<string> { "1080p", "720p", "5m", "4m", "8m", "ntsc", "pal", "720h", "960h" };

        public List<string> FFormat = new List<string> { "30fps", "25fps", "20fps", "15fps", "12fps", "60fps", "50fps" };

        public List<string> SFormat = new List<string> { "1080p_scale", "720p_scale", "4M_scale", "8M_scale", "1080pscale", "720pscale", "4Mscale", "8Mscale" };

        public string PathName
        {
            get
            {
                string str = string.Empty;
                string str125 = string.Empty;
                for (int i = 0; i < VFormat.Count; i++)
                {
                    for (int j = 0; j < FFormat.Count; j++)
                    {
                        if (FileName.ToLower().Contains("ntsc") || FileName.ToLower().Contains("pal"))
                        {
                            if (FileName.ToLower().Contains($"{VFormat[i].ToLower()}"))
                            {
                                str = $"{StandardName}_{VFormat[i]}";
                                if (FileName.ToLower().Contains("ntsc"))
                                {
                                    str = $"{StandardName}_{VFormat[i]}_ntsc";
                                }
                                else if (FileName.ToLower().Contains("pal"))
                                {
                                    str = $"{StandardName}_{VFormat[i]}_pal";
                                }
                                if (FileName.ToLower().Contains("scale"))
                                {
                                    if (FileName.ToLower().Contains("ntsc"))
                                    {
                                        sensorName = $"720p60fps";
                                    }
                                    else if (FileName.ToLower().Contains("pal"))
                                    {
                                        sensorName = $"720p50fps";
                                    }
                                    else
                                    {
                                        sensorName = $"{VFormat[i]}";
                                    }
                                }
                                else
                                {
                                    if (FileName.ToLower().Contains("ntsc"))
                                    {
                                        sensorName = $"{VFormat[i]}60fps";
                                    }
                                    else if (FileName.ToLower().Contains("pal"))
                                    {
                                        sensorName = $"{VFormat[i]}50fps";
                                    }
                                    else
                                    {
                                        sensorName = $"{VFormat[i]}";
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (FileName.ToLower().Contains($"{VFormat[i].ToLower()}{FFormat[j].ToLower()}"))
                            {
                                str125 = FFormat[j];
                                if (str125 == "12fps")
                                {
                                    str125 = "12.5fps";
                                }
                                str = $"{StandardName}_{VFormat[i]}{str125}";

                                sensorName = $"{VFormat[i]}{str125}";
                            }
                        }

                        if (FileName.ToLower().Contains("scale"))
                        {
                            for (int v = 0; v < SFormat.Count; v++)
                            {
                                for (int z = 0; z < FFormat.Count; z++)
                                {
                                    if (FileName.ToLower().Contains(SFormat[v].ToLower()) && FileName.ToLower().Contains(FFormat[z].ToLower()))
                                    {
                                        if (v < 4)
                                        {
                                            str125 = FFormat[z];
                                            if (str125 == "12fps")
                                            {
                                                str125 = "12.5fps";
                                            }
                                            sensorName = $"{SFormat[v].Split(new char[1] { '_' })[0]}{str125}";
                                        }
                                        else if (v >= 4)
                                        {
                                            str125 = FFormat[z];
                                            if (str125 == "12fps")
                                            {
                                                str125 = "12.5fps";
                                            }
                                            sensorName = $"{SFormat[v].Replace("scale", "")}{str125}";
                                        }
                                        // str = $"{StandardName}_{sensorName}";
                                    }

                                }

                            }
                        }
                    }
                }
                //if (FileName.ToLower().Contains("scale"))
                //{

                //}
                //else {

                //}


                return str;
            }
        }



        public string sensorName { get; set; }


        /// <summary>
        /// 时序名称
        /// </summary>
        public string TimingName
        {
            get
            {
                var TFileName = FileName;
                List<string> SFormats = new List<string> { "1080pscale", "720pscale", "4Mscale", "8Mscale" };
                for (int z = 0; z < SFormats.Count; z++)
                {
                    if (TFileName.ToLower().Contains(SFormats[z]))
                    {
                        TFileName = TFileName.ToLower().Replace("scale", "_scale_");
                    }
                }
                var iarr = TFileName.Split(new char[1] { '_' });
                string FileNamei = "";
                for (int i = 0; i < iarr.Length; i++)
                {
                    if (!iarr[i].ToLower().Contains("scale"))
                    {
                        FileNamei += iarr[i].ToString() + "_";
                    }
                }
                if (FileNamei.ToLower().Contains("1080p") && FileNamei.ToLower().Contains("30fps"))
                {
                    return "1080p30";
                }
                else if (FileNamei.ToLower().Contains("1080p") && FileNamei.ToLower().Contains("25fps"))
                {
                    return "1080p25";
                }
                else if (FileNamei.ToLower().Contains("720p") && FileNamei.ToLower().Contains("30fps"))
                {
                    return "720p30";
                }
                else if (FileNamei.ToLower().Contains("720p") && FileNamei.ToLower().Contains("25fps"))
                {
                    return "720p25";
                }
                else if (FileNamei.ToLower().Contains("960h") && FileNamei.ToLower().Contains("ntsc"))
                {
                    return "ntsc60fps";
                }
                else if (FileNamei.ToLower().Contains("960h") && FileNamei.ToLower().Contains("pal"))
                {
                    return "pal50fps";
                }
                else if (FileNamei.ToLower().Contains("720h") && FileNamei.ToLower().Contains("ntsc"))
                {
                    return "720h60fps";
                }
                else if (FileNamei.ToLower().Contains("720h") && FileNamei.ToLower().Contains("pal"))
                {
                    return "720h50fps";
                }
                else if (FileNamei.ToLower().Contains("5m") && FileNamei.ToLower().Contains("20fps"))
                {
                    return "5M20";
                }
                else if (FileNamei.ToLower().Contains("5m") && FileNamei.ToLower().Contains("12fps"))
                {
                    return "5M12.5";
                }
                else if (FileNamei.ToLower().Contains("4m") && FileNamei.ToLower().Contains("30fps"))
                {
                    return "4M30";
                }
                else if (FileNamei.ToLower().Contains("4m") && FileNamei.ToLower().Contains("12fps"))
                {
                    return "4M12.5";
                }
                else if (FileNamei.ToLower().Contains("4m") && FileNamei.ToLower().Contains("15fps"))
                {
                    return "4M15";
                }
                else if (FileNamei.ToLower().Contains("4m") && FileNamei.ToLower().Contains("25fps"))
                {
                    return "4M25";
                }
                else if (FileNamei.ToLower().Contains("8m") && FileNamei.ToLower().Contains("12fps"))
                {
                    return "8M12.5";
                }
                else if (FileNamei.ToLower().Contains("8m") && FileNamei.ToLower().Contains("15fps"))
                {
                    return "8M15";
                }
                else if (FileNamei.ToLower().Contains("8m") && FileNamei.ToLower().Contains("25fps"))
                {
                    return "8M25";
                }
                else
                {
                    return null;
                }

            }
        }
        /// <summary>
        /// setting分区X
        /// </summary>
        public string SetPartitions
        {
            get
            {
                if (FileName.ToLower().Contains("ahd") || FileName.ToLower().Contains("thd") || FileName.ToLower().Contains("chd") || FileName.ToLower().Contains("cvbs"))
                {
                    //var iarr = FileName.Split(new char[1] { '_' });
                    //return iarr[3].ToString().Replace("setting","");
                    return null;

                }
                else
                {
                    var iarr = FileName.Split(new char[1] { '_' });
                    return iarr[0].ToString().Replace("setting", "");
                }

            }
        }
        /// <summary>
        /// setting套数{X}
        /// </summary>
        public string SetNumber
        {
            get
            {
                if (FileName.ToLower().Contains("ahd") || FileName.ToLower().Contains("thd") || FileName.ToLower().Contains("chd") || FileName.ToLower().Contains("cvbs"))
                {
                    //var iarr = FileName.Split(new char[1] { '_' });
                    //return iarr[4].ToString().Replace("[","").Replace("]","");
                    return null;

                }
                else
                {
                    var iarr = FileName.Split(new char[1] { '_' });
                    return iarr[1].ToString().Replace("[", "").Replace("]", "");
                }

            }
        }

        public bool IsChecked { get; set; }

        public int Tag
        {
            get; set;
        }




    }
}
